import DayNewlyAddLine from '@/pages/statistic/DayNewlyAddLine';
import { dayNewlyAddedTaskUsingPost } from '@/services/backend/userController';
import { PageContainer } from '@ant-design/pro-components';
import { Col, notification, Row } from 'antd';
import React, { useEffect, useState } from 'react';

const Statistic: React.FC = () => {
  //添加信息
  const [userData, setUserData] = useState<DayNewlyAdd[]>([]);
  const loadUserStatistics = async () => {
    try {
      const { data, code } = await dayNewlyAddedTaskUsingPost();
      if (code === 0 && data) {
        const newData = data.map((item) => {
          return {
            ...item,
            num: Number(item.num),
          };
        });
        setUserData(newData);
      }
    } catch (e: any) {
      notification.error({
        message: '系统异常',
        description: e.message,
      });
    }
  };

  //页面加载时的钩子
  useEffect(() => {
    //加载数据
    loadUserStatistics();
  }, []);

  return (
    <PageContainer>
      <Row gutter={24}>
        <Col
          span={12}
          style={{
            marginBottom: 24,
          }}
        >
          <DayNewlyAddLine title={'近30日新增用户统计'} data={userData} />
        </Col>
        <Col
          span={12}
          style={{
            marginBottom: 24,
          }}
        >
          <DayNewlyAddLine title={'近30日新增用户统计2'} data={userData} />
        </Col>
      </Row>
    </PageContainer>
  );
};

export default Statistic;
